package com.rpframework.website.device.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.rpframework.core.BaseService;
import com.rpframework.utils.NumberUtils;
import com.rpframework.utils.Pager;
import com.rpframework.website.device.dao.IBankDao;
import com.rpframework.website.device.domain.Bank;
	
@Service
public class BankService extends BaseService{
	public @Resource IBankDao iDao;

	
	public Pager<Bank> getPager(Pager<Bank> pager) {
		long startTime = System.currentTimeMillis();
		List<Bank> itemList = iDao.doPager(this.packageMyBatisParam(pager));
		pager.setItemList(itemList);
		pager.setCostTime(System.currentTimeMillis()-startTime);
		return pager;
	}


	public boolean doSaveOrUpdate(Bank t) {
		if(NumberUtils.isValid(t.getId())){
			Bank db = iDao.select(t.getId());
			if(t.getImage() == null){
				t.setImage(db.getImage());
			}
			t.setModifyTime(System.currentTimeMillis()/1000);
			return iDao.update(t);
		}else{
			t.setCreateTime(System.currentTimeMillis()/1000);
			t.setState(1);
			return iDao.insert(t);
		}
	}
}
